/**
 * 文章管理相关的js
 */
$(document).ready(function(){
	var initdata = {"CName":"", "CNamee":"", "CTitle":"", "CTitlee":"", "CSortid":"", "startdate":"", "enddate":""};
	var jsonString = JSON.stringify(initdata);
	$("#condition").val(jsonString);
});
function selectCheckbox() {
	if ($('#all').attr('checked') == 'checked') {
		/* 全选多选框 */
		$("input[type='checkbox']").prop("checked", true);
	}
	if ($('#all').attr('checked') != 'checked') {
		/* 全不选多选框 */
		$("input[type='checkbox']").prop("checked", false);
	}
}
//保存文章类别
function SaveArticleManagement(formid, requestUrl) {
	var result = SaveForm(formid, requestUrl);
	alert(result);
}
//删除文章类别
function DeleteArticleCategory(value, requestUrl) {
	if(confirm("您确定要删除该文章类别吗？")){
		var result = AjaxRequest(requestUrl+"?id="+value);
		var curpage = $("#currentpage").val();
		var psize = $("#pagesize").val();
		var tr = $("#articlecategoryTb tr");
		if(result == "DeleteSuccess"){
			if(tr.length-1 == 2){
				location.href="/CMSProject/ArticleManagement_ArticleCategoryManagement?currentPage="+(curpage-1)+"&pageSize="+psize;
			}else{
				location.reload(true);
			}
			alert("删除文章类别成功");
		}else{
			alert("您要删除的文章类别已不存在");
		}
	}
}

//批量删除文章类别
function batchDeleteArticleCategory() {
	if(confirm("您确定要删除该文章类别吗？")){
		x = $(":checked").parent().children(".simple").toArray();
		var list = new String;
		for(var i=0;i<$(":checked").parent().children(".simple").length;i++){
			list=list+x[i].value+",";
		}
		var result = AjaxRequest("/CMSProject/ArticleManagement_batchDeleteArticleCategory?list="+list);
		var curpage = $("#currentpage").val();
		var psize = $("#pagesize").val();
		var tr = $("#articlecategoryTb tr");
		if(result == "BatchDeleteSuccess"){
			if(tr.length-$(":checked").parent().children(".simple").length == 2){
				location.href="/CMSProject/ArticleManagement_ArticleCategoryManagement?currentPage="+(curpage-1)+"&pageSize="+psize;
			}else{
				location.reload(true);
			}
			alert("批量删除成功");
		}else{
			if(result == "PartNotExist"){
				alert("部分记录已不存在");
			}else{
				if(result == "DataIsNull"){
					alert("未选中记录");
				}else{
					alert(result);
				}
			}
		}
	}
}
//删除文章
function DeleteArticle(value, requestUrl) {
	if(confirm("您确定要删除这篇文章吗？")){
		var result = AjaxRequest(requestUrl+"?id="+value);
		var curpage = $("#currentpage").val();
		var psize = $("#pagesize").val();
		var tr = $("#articleTb tr");
		if(result == "文章删除成功"){
			if(tr.length-1 == 2){
				location.href="/CMSProject/ArticleManagement_ArticleManagement?currentPage="+(curpage-1)+"&pageSize="+psize;
			}else{
				location.reload(true);
			}
			alert(result);
		}else{
			alert(result);
		}
	}
}
//批量删除文章
function batchDeleteArticle() {
	if(confirm("您确定要删除选中的文章吗？")){
		x = $(":checked").parent().children(".simple").toArray();
		var list = new String;
		for(var i=0;i<$(":checked").parent().children(".simple").length;i++){
			list=list+x[i].value+",";
		}
		var result = AjaxRequest("/CMSProject/ArticleManagement_batchDeleteArticle?list="+list);
		var curpage = $("#currentpage").val();
		var psize = $("#pagesize").val();
		var tr = $("#articleTb tr");
		if(result == "批量删除成功"){
			if(tr.length-$(":checked").parent().children(".simple").length == 2){
				location.href="/CMSProject/ArticleManagement_ArticleManagement?currentPage="+(curpage-1)+"&pageSize="+psize;
			}else{
				location.reload(true);
			}
			alert(result);
		}else{
			alert(result);
		}
	}
}
//添加查询条件
//{"CName":"","CNamee":"","startdate":"","enddate":""}
var data = {"CName":"", "CNamee":"", "CTitle":"", "CTitlee":"", "CSortid":"", "startdate":"", "enddate":""};
function addcondition(obj) {
	//data = {"CName":"","CNamee":"","startdate":"","enddate":""};
	data[obj.id] = obj.value;
	var jsonString = JSON.stringify(data);
	$("#condition").val(jsonString);
}


















